/************************************************************************/
/*    author  vinee.han
/*    time    2015/06/05
/*    wikioi                                                                     */
/************************************************************************/
/*
#include <iostream>
using namespace std;

struct MyNode
{
	int data,left,right;
}Tr[100];

void createBT(int d,int l,int r)
{
	Tr[d].data = d;
	Tr[d].left = l;
	Tr[d].right = r;
}

void preOrder(int d)
{
	if(Tr[d].data == 0)
		return;
	cout<<Tr[d].data<<" ";
	preOrder(Tr[d].left);
	preOrder(Tr[d].right);
}

void inOrder(int d)
{
	if(Tr[d].data == 0)
		return;
	inOrder(Tr[d].left);
	cout<<d<<" ";
	inOrder(Tr[d].right);
}

void posOrder(int d)
{
	if(Tr[d].data == 0)
		return;
	posOrder(Tr[d].left);
	posOrder(Tr[d].right);
	cout<<d<<" ";
}

int main()
{
	int n;
	cin>>n;
	int l,r;
	for (int i=1;i<=n;i++)
	{
		cin>>l>>r;
		createBT(i,l,r);
	}
	preOrder(1);
	cout<<endl;
	inOrder(1);
	cout<<endl;
	posOrder(1);
	return 0;
}*/